#!/bin/bash
#
# xCdnServerd        Startup script for the xCdnServer
#
# chkconfig: - 85 15
# description: The xCdnServer is an efficient and extensible  \
#	       server implementing the current HTTP standards.
# processname: xCdnServerd


# Source function library.
. /etc/rc.d/init.d/functions


# Path to the xCdnServerd script, server binary, and short-form for messages.
RETVAL=0
xCdnServerd=/usr/local/sbin/xCdnServer/xCdnServer
prog=xCdnServerd
lockfile=/var/lock/subsys/$prog
STOP_TIMEOUT=${STOP_TIMEOUT-10}


# set server start file des max numbers
# server must start confit at max conenction 65536 / 2 = 32768  ,and max stack memory 10240 KB=10MB
ulimit  -n  65536
ulimit  -s  10240


# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        daemon $xCdnServerd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping xCdnServerd, a delay (of default 10 second) is required
# before SIGKILLing the xCdnServerd parent; this gives enough time for the
# xCdnServerd parent to SIGKILL any errant children.
stop() {
	echo -n $"Stopping $prog: "
	killproc  -d ${STOP_TIMEOUT} $xCdnServerd
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile}
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;; 
  status)
    status $xCdnServerd
	RETVAL=$?
	;;
  restart)
	stop
	start
	;; 
  reload)
	exit 3
	;;
  *)
	echo $"Usage: $prog {start|stop|restart}"
	RETVAL=2
esac

exit $RETVAL



#如何增加一个服务：
#1.服务脚本必须存放在/etc/ini.d/目录下；
#2.chkconfig --add servicename
# 在chkconfig工具服务列表中增加此服务，此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了；
#3.chkconfig --level 35 mysqld on
# 修改服务的默认启动等级。
